﻿@page
@model Emprise.Web.Pages.User.SendVerifyEmailModel
@{
    ViewData["Title"] = "验证邮箱";
}
@{
    Layout = "_Layout";
}
<div class="big_bg" id="app">
    <div class="nav">
        <h2 class="nav-title">验证邮箱</h2>
        <div style="position: absolute; top: 10px; right: 10px;"><a style="font-size:12px;padding:0 5px;" href="@(Url.Page("/User/Logout"))" class="btn btn-small-tawny">退出</a></div>
    </div>

    <div class="main">
        <div>
            <div class="login-nonreg">
                <form>
                    <div class="form-text-login">
                        <label>邮箱：</label>
                        <input type="text" readonly class="form-text" v-model="email" />
                        <a href="javascript:;" class="form-text-clear fn-hide"><i class="icon icon-clear"></i></a>
                    </div>

                </form>
            </div>
            <div class="fn-mt-login fn-mlr">
                <a class="btn btn-bar-tawny" href="javascript:;" v-on:click="send"> 发送邮件 </a>
            </div>
            <div class="fn-mt-login fn-mlr">
                <a class="btn btn-bar-tawny" href="@(Url.Page("/User/VerifyEmail"))"> 我已发送邮件，直接进入验证界面 </a>
            </div>

            <div class="fn-mt fn-mlr mt15"><span class="tips">{{tips}}</span></div>
            <div class="fn-mt-login fn-mlr" style="text-align:right;">
                <a style="font-size:12px;" href="@(Url.Page("/User/Index"))">暂不验证，返回个人中心</a>
            </div>
        </div>

    </div>



    <div class="loading" v-show="loading">
        <img src="/images/loading.gif">
    </div>
</div>

@await Html.PartialAsync("_Footer", Model.SiteConfig)
@section Scripts {
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                email: "@(Model.Email)",
                tips: "",
                loading: 0,
            },
            computed: {
                loginUrl:function(){
                    return "/user/login?email=" + this.emailToLower;
                },
                regUrl: function () {
                    return "/user/reg?email=" + this.emailToLower;
                },
                emailToLower: function () {
                    return this.email.toLowerCase();
                }
            },
            methods: {
                send: function () {
                    var that = this;
                    that.tips = "";

                    if (!that.email) {
                        that.tips = "请输入邮箱";
                        return false;
                    }

                    that.loading = 1;

                    axios.post("", {
                        email: that.email
                    }, {
                        headers: {
                            RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value
                        }
                    })
                    .then(function (response) {
                        var result = response.data;
                        if (result.status) {
                             location.href = "@(Url.Page("/User/VerifyEmail"))";
                        } else {
                            var error = result.errorMessage || "发送邮件失败";
                            if (result.data) {
                                error += "<br>" + result.data;
                            }
                            that.tips = error;
                        }
                        that.loading = 0;
                    })
                    .catch(function (error) {
                        console.log(error);
                        that.loading = 0;
                    });
                }
            }
        });

    </script>
}